home *** CD-ROM | disk | FTP | other *** search
- Path: netnews.research.nokia.com!wikman
- From: wikman@falcon.research.nokia.com (Johan Wikman)
- Newsgroups: comp.lang.c++
- Subject: Re: Why use private class members instead of protected?
- Date: 14 Jan 1996 08:05:33 GMT
- Organization: Nokia Research Center
- Message-ID: <WIKMAN.96Jan14100533@falcon.research.nokia.com>
- References: <30F4AB49.6ABB@sierra.net>
- <30F50874.15FB7483@intellektik.informatik.th-darmstadt.de>
- <4d3q07$n8o@geraldo.cc.utexas.edu>
- <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de>
- NNTP-Posting-Host: falcon.research.nokia.fi
- In-reply-to: Enno Sandner's message of Fri, 12 Jan 1996 09:32:44 +0100
-
-
- In article <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de> Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
-
- However an accessor/mutator pair like
-
- void MyClass :: set_data(const DataType&) { ... }
- DataType MyClass :: get_data() const { return _data; }
-
- completely avoids this sort of problems. If the 'DataType' uses some
- technique to speed up copying (for example ref-counting) the overhead
- is minimal.
-
- I think you only change the problem into something else. Now if you
- ever choose to change the representation of '_data' you face the
- problem of converting a DataType to and from whatever type '_data'
- is. The problem is still there, it has only changed shape.
-
- In my opinion it fairly seldom makes sense to provide accessor/mutator
- functions to the data members of a class. In fact, I get suspicious
- when a class reminds you of a data repository instead of reminding you
- of something that provides behaviour.
-
- Johan
- --
- johan.wikman@research.nokia.com
-